package treeTest;

public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }

    TreeNode() {
    }

    ;

    /*
     * 先序遍历
     * */
    public void preOrder() {
        System.out.println(this.val);
        if (this.left != null) {
            this.left.preOrder();
        }
        if (this.right != null) {
            this.right.preOrder();
        }
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "val=" + val +
                ", left=" + left +
                ", right=" + right +
                '}';
    }

    public static int maxDepth(TreeNode root) {
        if (root == null) return 0;
        int l = maxDepth(root.left);
        int r = maxDepth(root.right);
        return Math.max(l, r) + 1;
    }

    public static void main(String[] args) {
//        TreeNode root = new TreeNode(0);
//        TreeNode left = new TreeNode(1);
//        TreeNode left1 = new TreeNode(2);
//        root.left=left;
//        left.left=left1;
//        TreeNode right = new TreeNode();
//        root.right = right;
//        System.out.println(maxDepth(root));

        for (int i = 0; i < 10; i++) {
            try {
                if (i == 5) {
                    System.out.println(i / 0);
                }
                System.out.println(i);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}
